#include "lru_cache.h"
#include <iostream>
#include <string>

int main() {
    std::cout << "\n====== C++11 LRU缓存简单测试 ======\n" << std::endl;

    // 创建一个容量为3的LRU缓存，存储<int, string>键值对
    LRUCache<int, std::string> cache(3);

    // 1. 插入数据
    std::cout << "1. 插入3个数据项：" << std::endl;
    cache.put(1, "第一条数据");
    cache.put(2, "第二条数据");
    cache.put(3, "第三条数据");
    std::cout << "   已插入: 1->\"第一条数据\", 2->\"第二条数据\", 3->\"第三条数据\"" << std::endl;
    std::cout << "   当前缓存大小: " << cache.size() << "/" << cache.capacity() << std::endl;

    // 2. 读取数据
    std::cout << "\n2. 读取key=2的数据：" << std::endl;
    std::string value;
    if (cache.get(2, value)) {
        std::cout << "   找到: key=2, value=\"" << value << "\"" << std::endl;
    }

    // 3. LRU淘汰测试
    std::cout << "\n3. 插入第4条数据（将触发LRU淘汰）：" << std::endl;
    cache.put(4, "第四条数据");
    std::cout << "   已插入: 4->\"第四条数据\"" << std::endl;

    // 验证key=1是否被淘汰
    if (!cache.contains(1)) {
        std::cout << "   key=1已被淘汰（最久未使用）✓" << std::endl;
    }

    // 4. 显示当前缓存内容
    std::cout << "\n4. 当前缓存内容：" << std::endl;
    for (int key : {1, 2, 3, 4}) {
        if (cache.get(key, value)) {
            std::cout << "   key=" << key << " -> \"" << value << "\"" << std::endl;
        }
    }

    // 5. 统计信息
    std::cout << "\n5. 缓存统计信息：" << std::endl;
    std::cout << "   缓存大小: " << cache.size() << "/" << cache.capacity() << std::endl;
    std::cout << "   总访问次数: " << cache.getTotalAccess() << std::endl;
    std::cout << "   命中次数: " << cache.getHitCount() << std::endl;
    std::cout << "   未命中次数: " << cache.getMissCount() << std::endl;
    std::cout << "   命中率: " << (cache.getHitRate() * 100) << "%" << std::endl;

    std::cout << "\n====================================\n" << std::endl;

    return 0;
}